package com.ocean.clearance.controller;


import java.util.List;
import java.util.UUID;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.metadata.Sheet;
import com.ocean.clearance.controller.dto.JavaModel;
import com.ocean.clearance.controller.dto.UserBean;

import EasyExcelFactory.ExcelListener;
import lombok.SneakyThrows;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
public class DemoController {

	@Autowired
	RabbitTemplate rabbitTemplate;
	
	@GetMapping("hello")
	public Mono<String> testMono() {
		return Mono.just("world!!!");
	}

	@PostMapping("add_user")
	public Flux<String> add(@RequestBody UserBean users) {
		return Flux.just(users.getUserName());
	}
	
	/*@PostMapping("msg_producer")
	public void produceMsg(@RequestParam(required = true) String foo) {//direct模式
		rabbitTemplate.convertAndSend("direct.exchange","key.1",foo,new CorrelationData(UUID.randomUUID().toString()));
	}*/
	
	@PostMapping("msg_producer2")
	public void produceMsg2(@RequestParam(required = true) String foo) {//direct模式
		rabbitTemplate.convertAndSend("delay-recevice-ex","#",foo,new CorrelationData(UUID.randomUUID().toString()));
	}
	
	@PostMapping("read_excel")
	@SneakyThrows
	public Object add(MultipartFile excel) {
		List<Object> data1 = EasyExcelFactory.read(excel.getInputStream(), new Sheet(1, 0));//读07版小于1000行数据返回List<List<String>>
		
		List<Object> data2 = EasyExcelFactory.read(excel.getInputStream(), new Sheet(2, 1,JavaModel.class));//读07版小于1000行数据返回List<? extend BaseRowModel>
		
		ExcelListener excelListener1 = new ExcelListener();
		EasyExcelFactory.readBySax(excel.getInputStream(), new Sheet(1, 1), excelListener1);//读07版大于1000行数据返回List<List<String>>
		
		ExcelListener excelListener2 = new ExcelListener();
		EasyExcelFactory.readBySax(excel.getInputStream(), new Sheet(2, 1,JavaModel.class), excelListener2);//读07版大于1000行数据返回List<? extend BaseRowModel>
		return null;
	}
	
}
